@ECHO OFF
ECHO.
ECHO Running post build actions.
ECHO.

:: e.g."Debug" or "Release"
SET CONFIG=%1
SET CONFIG=%CONFIG:~1,-1%
ECHO CONFIG: %CONFIG%

:: e.g. "C:\Projects\MyWorkflowFeature"
SET PROJECTDIR=%2
SET PROJECTDIR=%PROJECTDIR:~1,-2%
ECHO PROJECTDIR: %PROJECTDIR%

:: e.g. "C:\Projects\MyWorkflowFeature\DeploymentFiles"
SET DEPLOYMENTDIR=%PROJECTDIR%\DeploymentFiles
ECHO DEPLOYMENTDIR: %DEPLOYMENTDIR%

:: e.g. "MyWorkflowFeature"
SET PROJECTNAME=%3
SET PROJECTNAME=%PROJECTNAME:~1,-1%
ECHO PROJECTNAME: %PROJECTNAME%

:: e.g. "C:\Projects\MyWorkflowFeature\bin\Debug"
SET TARGETDIR=%4
SET TARGETDIR=%TARGETDIR:~1,-2%
ECHO TARGETDIR: %TARGETDIR%

:: cmd parameter, e.g. "DEPLOY" or "NODEPLOY"
SET DEPLOY=%6
ECHO DEPLOY: %DEPLOY%

SET DEPLOYVALUE=DEPLOY
ECHO DEPLOYVALUE: %DEPLOYVALUE%

:: WSP manifest.xml and ddf file location, e.g. "C:\Projects\MyWorkflowFeature\DeploymentFiles\ProductionDeployment"
SET PRODUCTIONDIR=%DEPLOYMENTDIR%\ProductionDeployment
ECHO PRODUCTIONDIR: %PRODUCTIONDIR%

IF EXIST "%CommonProgramFiles%\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.EXE" (SET STSADM="%CommonProgramFiles%\Microsoft Shared\Web Server Extensions\12\BIN\STSADM.EXE") ELSE (ECHO STSAMD.EXE could not be found! & GOTO QUIT)

IF %CONFIG%==Debug GOTO QUIT

:: -----------------------------------------------
:RELEASE

ECHO.
ECHO Using ProductionDeployment
ECHO.

ECHO.
ECHO Generating %PROJECTNAME%.wsp ...
ECHO.

makecab /f "%PRODUCTIONDIR%\wsp_structure.ddf"

ECHO.
ECHO Deploying the feature:
ECHO.

IF NOT %DEPLOY%==%DEPLOYVALUE% (ECHO Skipping deployment & GOTO QUIT)

ECHO.
ECHO Deactiviating and uninstalling the feature...
ECHO.

%STSADM% -o deactivatefeature  -filename %PROJECTNAME%\feature.xml  -url http://localhost/  -force
%STSADM% -o uninstallfeature   -filename %PROJECTNAME%\feature.xml  -force

ECHO.
ECHO Retracting and deleting solution (if it exists)...
ECHO.

%STSADM% -o retractsolution    -name %PROJECTNAME%.wsp              -local
%STSADM% -o deletesolution     -name %PROJECTNAME%.wsp

ECHO.
ECHO Adding and deploying the solution...
ECHO.

%STSADM% -o addsolution        -filename "%TARGETDIR%\Package\%PROJECTNAME%.wsp"
%STSADM% -o deploysolution     -name %PROJECTNAME%.wsp              -local                  -allowGacDeployment  -force

ECHO.
ECHO Activating and installing the feature...
ECHO.

%STSADM% -o installfeature     -filename %PROJECTNAME%\feature.xml  -force
%STSADM% -o activatefeature    -filename %PROJECTNAME%\feature.xml  -url http://localhost/  -force

GOTO FINISH


:: -----------------------------------------------
:FINISH

ECHO Doing an iisreset...
ECHO.

CALL iisreset


:: -----------------------------------------------
:QUIT

ECHO.
ECHO Done
ECHO.